<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //获取实时时间对象 也可以获取某一时间的时间对象
        const date = new Date()
        const date1 =new Date('2021-5-1 08:30:00')
        const year = date.getFullYear()
        let month = date.getMonth() + 1
        month = month < 10 ? '0' + month : month  //补0
    </script>
</body>

</html>